<?php

//计算工资
//author:化缘

header("Content-type: text/html; charset=utf-8");
require('../mysql.php');
require('json.php');//导入生成json的函数包
require('computtime.php'); //导入计算时间差的函数
require('../unitpriceconfig.php');//导入单价配置页面



//取出所有当前一个月的所有工资
function getallecome(){
  //计算上个月的时间范围
    $year=date("Y");
    $month=date("m");
   
    $worktimebeginer=$year."-".$month."-"."01"." 00:00:00";
    $worktimeend=$year."-".$month."-"."31"." 00:00:00";

    //从计量表中取出数据
    $sqloncomputebysize="SELECT studentid,count,price,timebegin,timeend FROM computebysize WHERE timebegin >'{$worktimebeginer}' AND timebegin < '$worktimeend'";
    $result=mysql_query($sqloncomputebysize);
    
    $list=array();

    while ($row = mysql_fetch_assoc($result)) {
      
       $alltime=getworkhoures($row['timebegin'],$row['timeend']);
       $alltime=number_format($alltime,3,'.','');
       $price=$row['count']*$row['price'];
       $price=number_format($price,3,'.','');
       $pricefromcomputesize=array("studentid"=>$row['studentid'],"price"=>$price,"timebegin"=>$row['timebegin'],"workalltime"=>$alltime);
       $list[]=$pricefromcomputesize;
      // echo $row['count']*$row['price']."\n";
    }
   

    //从上书管理表中获取数据
    $sqlonbookmanage="SELECT studentid,count,timebegin,timeend FROM bookmanage WHERE timebegin >'{$worktimebeginer}' AND timebegin < '$worktimeend'";
    $resultbookmanage=mysql_query($sqlonbookmanage);

    while ($rowonbookmanage = mysql_fetch_assoc($resultbookmanage)) {
       $alltime=getworkhoures($rowonbookmanage['timebegin'],$rowonbookmanage['timeend']);
      $alltime=number_format($alltime,3,'.','');
       $price=$rowonbookmanage['count']*bookprice;
       $price=number_format($price,3,'.','');
       $pricefrombookmanage=array("studentid"=>$rowonbookmanage['studentid'],"price"=>$price,"timebegin"=>$rowonbookmanage['timebegin'],"workalltime"=>$alltime);
       $list[]= $pricefrombookmanage;
       
    }


    //从计时表获取数据
    $sqlontimecount="SELECT studentid,timebegin,timeend FROM timecount WHERE timebegin >'{$worktimebeginer}' AND timebegin < '$worktimeend'";
    $resulttimecount=mysql_query($sqlontimecount);

    while ($rowontimecount = mysql_fetch_assoc($resulttimecount)) {
       $alltime=getworkhoures($rowontimecount['timebegin'],$rowontimecount['timeend']);
        $alltime=number_format($alltime,3,'.','');
        $price=$alltime*timeprice;
       $price=number_format($price,3,'.','');
       $pricefrombookmanage=array("studentid"=>$rowontimecount['studentid'],"price"=>$price,"timebegin"=>$rowontimecount['timebegin'],"workalltime"=>$alltime);
       $list[]= $pricefrombookmanage;
       
    }

    //从报刊管理表获取数据
    $sqlonnewspapers="SELECT studentid,count,timebegin,timeend FROM newspapers WHERE timebegin >'{$worktimebeginer}' AND timebegin < '$worktimeend'";
    $resultnewspapers=mysql_query($sqlonnewspapers);

    while ($rowonnewspapers = mysql_fetch_assoc($resultnewspapers)) {
       $alltime=getworkhoures($rowonnewspapers['timebegin'],$rowonnewspapers['timeend']);
       $alltime=number_format($alltime,3,'.','');
       $price=$alltime*newspaperprice;
       $price=number_format($price,3,'.','');
       $pricefrombookmanage=array("studentid"=>$rowonnewspapers['studentid'],"price"=>$price,"timebegin"=>$rowonnewspapers['timebegin'],"workalltime"=>$alltime);
       $list[]= $pricefrombookmanage;
       
    }


    return $list;
 }


//取出当前月的所有工作的数据
function getallname(){
   $list=array();
   $list=getallecome();
    $info=array();
    $output=array();
   
        for ($j=0; $j <count($list) ; $j++) { 
  
    
             $stuid=$list[$j]['studentid'];
              $stringsql="SELECT studentname,college FROM allstudent WHERE studentid = '{$stuid}' ";
                  $result=mysql_query($stringsql);
    
                 while ($row = mysql_fetch_assoc($result)) {
           
                     $info[]=$row;

     
                 }
    
   
    }
 

  for ($i=0; $i <count($info) ; $i++) { 
    $output[]=$info[$i]+$list[$i];
  
   
  }
 
  echo encode_json($output);
 
}
//getallecome();

getallname();


?>